import {Command} from '../constant';
import Taro, {getCurrentInstance} from '@tarojs/taro';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';
import api from 'api';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },
    async page() {
      let {id} = getCurrentInstance().router.params;
      let params = {
        id,
      };
      let result = await api.pagesIndexController.getMarketingcontentDetail(params);
      if (result.code == 'K-000000') {
        action.commonChange([{paths: 'main.detail', value: result.context}]);
      }
    },
    async addThumb(params) {
      await api.forumController.addThumb(params);
    },
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageCArticleDetailMain'),
  };
}

//create by moon https://github.com/creasy2010/moon
